home *** CD-ROM | disk | FTP | other *** search
/ Super CD 5 / Super CD 5 (Groupware).bin / os2 / cimgcp.cmd < prev    next >
OS/2 REXX Batch file  |  1994-05-21  |  6KB  |  188 lines

  1. /* CIMGCP.CMD Copyright 1994 by William J. Hinkle [75300,2050] */
  2. /* This Rexx script translates WinCIM address books to GCP USERID.CIS
  3.    Just run it from an OS/2 command line or a desktop program object
  4.    If you have trouble with this, I'd like to hear about it, but: 
  5.    "Use this at your own risk: all responsibility is disclaimed!"
  6.    This is free for individuals to use and distribute.
  7. */
  8. uppert = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  9. lowert = "abcdefghijklmnopqrstuvwxyz"
  10. SIGNAL ON HALT
  11.  
  12. gcpok = ""
  13. DO UNTIL gcpok = "READY:"
  14.     IF gcpok <> "" THEN DO
  15.         SAY
  16.         SAY gcpaddr "could not be found."
  17.         SAY "Hint: check your Golden CommPass directory!"
  18.     END
  19.     SAY "Please enter the drive:path to the Golden CommPass Address Book USERID.CIS."
  20.     SAY "Just [Enter] for C:\GCP\ or [Ctrl+C][Enter] to quit: ";
  21.     PARSE PULL gcppath
  22.     cimpath = STRIP(gcppath,"B")
  23.     IF gcppath = "" THEN
  24.         gcppath = "C:\GCP\"
  25.     ELSE DO
  26.         IF RIGHT(gcppath,1) <> "\" & RIGHT(gcppath,1) <> ":" THEN DO
  27.             gcppath = gcppath || "\"
  28.         END
  29.     END
  30.     gcpaddr = gcppath || "USERID.CIS"
  31.     IF STREAM(gcpaddr,"C","QUERY EXISTS") <> "" THEN DO
  32.     SAY "Did you already save" gcpaddr "just in case...? [Y/N][Enter]:"
  33.     PARSE UPPER PULL strdat
  34.     IF strdat <> "Y" THEN DO
  35.         SAY "You'd better do that right now, and try this again later!"
  36.         EXIT
  37.     END
  38.     END
  39.     gcpok = STREAM(gcpaddr,"C","OPEN WRITE")
  40. END
  41.  
  42. SAY
  43.  
  44. cimok = ""
  45. DO UNTIL cimok = "READY:"
  46.     IF cimok <> "" THEN DO
  47.         SAY
  48.         SAY cimaddr "could not be found."
  49.         SAY "Hint: check your DOS CIM directory, or CSERVE\SUPPORT for WinCIM"
  50.     END
  51.     SAY "Please enter the drive:directory to the CIM Address Book ADDRBOOK.DAT."
  52.     SAY "Just [Enter] for C:\CSERVE\SUPPORT\ or [Ctrl+C][Enter] to quit: ";
  53.     PARSE PULL cimpath
  54.     cimpath = STRIP(cimpath,"B")
  55.     IF cimpath = "" THEN
  56.         cimpath = "C:\CSERVE\SUPPORT\"
  57.     ELSE DO
  58.         IF RIGHT(cimpath,1) <> "\" & RIGHT(cimpath,1) <> ":" THEN DO
  59.             cimpath = cimpath || "\"
  60.         END
  61.     END
  62.     cimaddr = cimpath || "ADDRBOOK.DAT"
  63.     cimok = STREAM(cimaddr,"C","OPEN READ")
  64. END
  65.  
  66. SAY
  67. IF cimok = "READY:" & gcpok = "READY:" THEN DO
  68.     cimtype = C2D(CHARIN(cimaddr,1,1))
  69.     IF cimtype = 1 THEN DO
  70.         SAY "DOS CIM Address Book"
  71.         slen = 1
  72.     END
  73.     ELSE IF cimtype = 2 THEN DO
  74.         SAY "WinCIM Address Book"
  75.         slen = 2
  76.     END
  77.     ELSE DO
  78.         SAY "Unknown CIM address book type:" cimtype
  79.         SIGNAL HALT
  80.     END
  81.  
  82.     nnames = C2D(REVERSE(CHARIN(cimaddr,2,slen)),slen)
  83.     cimpos = 2 + slen
  84.     SAY "There are" nnames "names and/or groups:"
  85.  
  86.     ncnt = 0
  87.     isagroup = 0
  88.     group.0.0 = 0
  89.     DO nnames
  90.         IF cimtype = 2 THEN DO
  91.             /* get the name index (+32768 if group) */
  92.             ncnt = C2D(REVERSE(CHARIN(cimaddr,cimpos,2)))
  93.             cimpos = cimpos + 2
  94.             isagroup = (ncnt >= 32768)
  95.             IF isagroup THEN ncnt = ncnt - 32768
  96.         END
  97.         ELSE ncnt = ncnt + 1
  98.  
  99.         /* get the name */
  100.         slen = C2D(CHARIN(cimaddr,cimpos,1))
  101.         strdat = CHARIN(cimaddr,cimpos+1,slen)
  102.         cimpos = cimpos + 1 + slen
  103.         IF isagroup THEN DO    /* acquire group list of name indices */
  104.             nametxt = strdat
  105.             /* get the number of names in the group */
  106.             slen = C2D(CHARIN(cimaddr,cimpos,1))
  107.             cimpos = cimpos + 1
  108.             group.0.0 = group.0.0 + 1
  109.             gcnt = group.0.0
  110.             group.0.gcnt = nametxt
  111.             group.gcnt.0 = slen
  112.             DO gix = 1 TO slen
  113.                 group.gcnt.gix = C2D(REVERSE(CHARIN(cimaddr,cimpos,2)),2)
  114.                 cimpos = cimpos + 2
  115.             END
  116.             /* skip 0-pad byte */
  117.             cimpos = cimpos + 1
  118.             nametxt = "Group:" nametxt "(" || slen "names)"
  119.         END
  120.         ELSE DO    /* acquire name information */
  121.             nametxt = ""
  122.             DO nsegcnt = 1 TO words(strdat)
  123.                 nameseg = WORD(strdat,nsegcnt)
  124.                 nametxt = nametxt || OVERLAY(TRANSLATE(SUBSTR(nameseg,2),lowert,uppert),nameseg,2) || " "
  125.             END
  126.  
  127.             /* get the PPN */
  128.             slen = C2D(CHARIN(cimaddr,cimpos,1))
  129.             strdat = STRIP(CHARIN(cimaddr,cimpos+1,slen),"B")
  130.             cimpos = cimpos + 1 + slen
  131.             nametxt = nametxt strdat
  132.  
  133.             /* get the comments */
  134.             slen = C2D(CHARIN(cimaddr,cimpos,1))
  135.             strdat = STRIP(CHARIN(cimaddr,cimpos+1,slen),"B")
  136.             cimpos = cimpos + 1 + slen
  137.             IF strdat <> "" THEN DO
  138.                 /* un-comment this to change case of comments */
  139.                 /*
  140.                 strdat = OVERLAY(TRANSLATE(SUBSTR(strdat,2),lowert,uppert),strdat,2)
  141.                 */
  142.                 /* blank out any @b0x0A combos (CIM endline) and 0x0D0A (WINCIM) */
  143.                 eolpos = 1
  144.                 IF cimtype = 1 THEN DO FOREVER
  145.                     eolpos = POS("@b" || "0A"x,strdat,eolpos)
  146.                     IF eolpos = 0 THEN LEAVE
  147.                     strdat = DELSTR(strdat,eolpos,2)
  148.                 END
  149.                 ELSE IF cimtype = 2 THEN DO FOREVER
  150.                     eolpos = POS("0D0A"x, strdat,eolpos)
  151.                     IF eolpos = 0 THEN LEAVE
  152.                     strdat = DELSTR(strdat,eolpos,1)
  153.                 END
  154.                 strdat = TRANSLATE(strdat," ","0A"x)
  155.             END
  156.             nametxt = nametxt '|' strdat
  157.  
  158.             /* see if any group names can be appended */
  159.             DO gcnt = 1 TO group.0.0
  160.                 DO gix = 1 TO group.gcnt.0
  161.                     IF group.gcnt.gix = ncnt THEN DO
  162.                         nametxt = nametxt "[" || group.0.gcnt || "]"
  163.                         LEAVE gix
  164.                     END
  165.                 END
  166.             END
  167.         END
  168.  
  169.         /* mention the name on-screen */
  170.         SAY "#" ncnt "=" nametxt
  171.         /* write the new address for GCP if it isn't a group */
  172.         IF \ isagroup THEN DO
  173.             IF LINEOUT(gcpaddr,nametxt) <> 0 & \ isagroup THEN DO
  174.                 SAY "Gagged writing to" gcpaddr "!"
  175.                 LEAVE nnames
  176.             END
  177.         END
  178.     END
  179. END
  180.  
  181.  
  182. HALT:
  183. IF POS(cimok,"NOTREADY:") = 1 THEN SAY "Couldn't find the CIM address book file!"
  184. ELSE IF cimok = "READY:" THEN CALL STREAM cimaddr,"C","CLOSE"
  185. IF POS(gcpok,"NOTREADY:") = 1 THEN SAY "Couldn't find the GCP address book file!"
  186. ELSE IF gcpok <> "READY:" THEN CALL STREAM gcpaddr,"C","CLOSE"
  187. EXIT
  188.